import Scanner from "./Scanner";
import nextTokens from "./nextTokens";
export default function parseTemplateToTokens(templateStr) {
  let tokens = [];
  var scanner = new Scanner(templateStr);
  while (!scanner.eos()) {
    let words1 = scanner.scanUtil("{{");
    if (words1 !== '') {
      tokens.push(['text', words1]);
    }
    scanner.scan("{{");
    let words2 = scanner.scanUtil("}}");
    if (words2 !== '') {
      if (words2[0] == '/') {
        tokens.push(['/', words2.substring(1)]);
      } else if (words2[0] == '#') {
        tokens.push(['#', words2.substring(1)])
      } else {
        tokens.push(['name', words2]);
      }
    }
    scanner.scan("}}");
  }
  return nextTokens(tokens);
}